package com.cyrus.vueboot.controller.log;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cyrus.vueboot.common.R;
import com.cyrus.vueboot.divAnno.OpsLogAnnotation;
import com.cyrus.vueboot.error.BusinessError;
import com.cyrus.vueboot.error.CommonError;
import com.cyrus.vueboot.service.LoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/16
 */
@Controller
@RequestMapping("/LoginLog")
public class LoginLogController {
    @Autowired
    private LoginLogService loginLogService;

    @PostMapping("/Search")
    @ResponseBody
    public R Search(Integer page, Integer size, String key) {
        IPage iPage = loginLogService.Search(page, size, key);
        List records = iPage.getRecords();
        long total = iPage.getTotal();
        long size1 = iPage.getSize();
        return R.ok().data("records", records).data("total", total).data("size",size1);
    }


    @OpsLogAnnotation(module = "登录日志管理",description = "删除了登录日志")
    @PostMapping("/deleteLogs")
    @ResponseBody
    public R deleteLogs(Long[] ids) {
        try {
            loginLogService.deleteLogs(ids);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessError(CommonError.E_10002.getCode(), CommonError.E_10002.getMsg());
        }

    }
}
